import marked from 'marked'
import {hex_md5} from "@/utils/md5";

const Parser = marked.Parser
const originalTok = Parser.prototype.tok

export default function tok(pluginHandler) {
    let ret = ''
    if (this.token.type === 'plugin') {
        ret = '<div id="' + hex_md5(this.token.args) + '">' +
            '<' + this.token.name + ' args="' + this.token.args + '">'
        ret += pluginHandler(this.token)
        ret += '</' + this.token.name + '></div>'
    } else {
        ret = originalTok.call(this)
    }
    // console.debug(`[PLUGGABLE-MARKDOWN] tok, token: ${this.token.type}——\n${ret}`)
    return ret
}
